<?php
/*
$conn = mysql_connect('127.0.0.1','root','',3306);

mysql_query('set names utf8',$conn);
mysql_query('use 17koko_m',$conn);
*/

$conn = mysql_connect('203.195.162.47','17koko','YVfyutCMGR3yESST',3306);
mysql_query('set names utf8',$conn);
mysql_query('use m_17koko',$conn);

$action = !empty($_GET['action'])?addslashes($_GET['action']):'';

if($action == 'android'){
	
	$title = !empty($_POST['title'])?trim($_POST['title']):'';
	$size = !empty($_POST['size'])?trim($_POST['size']):'';
	$picture = !empty($_POST['picture'])?trim($_POST['picture']):'';
	$description = !empty($_POST['description'])?trim($_POST['description']):'';
	$category_id = !empty($_POST['category_id'])?trim($_POST['category_id']):0;

	$pic = !empty($_POST['pic'])?trim($_POST['pic']):'';
	$url = !empty($_POST['url'])?trim($_POST['url']):'';
	$time = time();
	
	preg_match_all('/.*?<img.*?src=\"(.*?)\".*?>.*?/s',$picture,$picarr);
	
	preg_match_all('/.*?<img.*?src=["\'](.*?)["\'].*?>.*?/s',$pic,$array);

	$picd = $picarr[1][0];
	$sql = "insert into 17koko_recommend (title,category_id,url,picture,description,type,breakid,size,createtime)
	values 
	('$title','1','$url','$picd','$description','1','1','$size','$time')";
	//echo $sql;
	if(mysql_query($sql,$conn)){
		
		$id = mysql_insert_id();

		foreach($array[1] as $val){
			$sql = "insert into 17koko_recommend_picture (recommend_id,picture) values ('$id','$val')";
			if(mysql_query($sql,$conn)){
				echo '发布成功';
			}
		}
		
	}
	
}elseif($action=='ios'){
	$title = !empty($_POST['title'])?trim($_POST['title']):'';
	$size = !empty($_POST['size'])?trim($_POST['size']):'';
	$picture = !empty($_POST['picture'])?trim($_POST['picture']):'';
	$description = !empty($_POST['description'])?trim($_POST['description']):'';
	$category_id = !empty($_POST['category_id'])?trim($_POST['category_id']):0;

	$pic = !empty($_POST['pic'])?trim($_POST['pic']):'';
	$url = !empty($_POST['url'])?trim($_POST['url']):'';
	$time = time();
	
	preg_match_all('/.*?<img.*?src=\"(.*?)\".*?>.*?/s',$picture,$picarr);
	
	preg_match_all('/.*?<img.*?src=["\'](.*?)["\'].*?>.*?/s',$pic,$array);

	$picd = $picarr[1][0];
	$sql = "insert into 17koko_recommend (title,category_id,url,picture,description,type,breakid,size,createtime)
	values 
	('$title','1','$url','$picd','$description','2','1','$size','$time')";
	//echo $sql;
	if(mysql_query($sql,$conn)){
		
		$id = mysql_insert_id();

		foreach($array[1] as $val){
			$sql = "insert into 17koko_recommend_picture (recommend_id,picture) values ('$id','$val')";
			if(mysql_query($sql,$conn)){
				echo '发布成功';
			}
		}
		
	}
}elseif($action=='ios_1'){
		$title = !empty($_POST['title'])?trim($_POST['title']):'';
	$size = !empty($_POST['size'])?trim($_POST['size']):'';
	$picture = !empty($_POST['picture'])?trim($_POST['picture']):'';
	$description = !empty($_POST['description'])?trim($_POST['description']):'';
	$category_id = !empty($_POST['category_id'])?trim($_POST['category_id']):0;
	$game_id = !empty($_POST['game_id'])?trim($_POST['game_id']):0;
	$pic = !empty($_POST['pic'])?trim($_POST['pic']):'';
	$url = !empty($_POST['url'])?trim($_POST['url']):'';
	$time = time();
	
	preg_match_all('/.*?<img.*?src=\"(.*?)\".*?>.*?/s',$picture,$picarr);
	
	preg_match_all('/.*?<img.*?src=\"(.*?)\".*?>.*?/s',$pic,$array);
	$picd = $picarr[1][0];
	$sql = "insert into 17koko_recommend (title,category_id,url,picture,description,type,breakid,size,createtime)
	values 
	('$title','1','$url','$picd','$description','2','2','$size','$time')";
	//echo $sql;
	if(mysql_query($sql,$conn)){
		
		$id = mysql_insert_id();

		foreach($array[1] as $val){
			$sql = "insert into 17koko_recommend_picture (recommend_id,picture) values ('$id','$val')";
			if(mysql_query($sql,$conn)){
				echo '发布成功';
			}
		}
		
	}
	
}elseif($action=='wp'){
		$title = !empty($_POST['title'])?trim($_POST['title']):'';
	$size = !empty($_POST['size'])?trim($_POST['size']):'';
	$picture = !empty($_POST['picture'])?trim($_POST['picture']):'';
	$description = !empty($_POST['description'])?trim($_POST['description']):'';
	$category_id = !empty($_POST['category_id'])?trim($_POST['category_id']):0;

	$pic = !empty($_POST['pic'])?trim($_POST['pic']):'';
	$url = !empty($_POST['url'])?trim($_POST['url']):'';
	$time = time();
	
	preg_match_all('/.*?<img.*?src=\"(.*?)\".*?>.*?/s',$picture,$picarr);
	
	preg_match_all('/.*?<img.*?src=\"(.*?)\".*?>.*?/s',$pic,$array);
	$picd = $picarr[1][0];
	$sql = "insert into 17koko_recommend (title,category_id,url,picture,description,type,breakid,size,createtime)
	values 
	('$title','1','$url','$picd','$description','3','1','$size','$time')";
	//echo $sql;
	if(mysql_query($sql,$conn)){
		
		$id = mysql_insert_id();

		foreach($array[1] as $val){
			$sql = "insert into 17koko_recommend_picture (recommend_id,picture) values ('$id','$val')";
			if(mysql_query($sql,$conn)){
				echo '发布成功';
			}
		}
		
	}
}elseif($action=='daoru'){
	
	$sql = "select * from 17koko_recommend order by id asc";
	$rs = mysql_query($sql,$conn);
	$array = array();
	while($row = mysql_fetch_assoc($rs)){
		$array[] = $row;
	}
	
	foreach($array as $key=>$val){
		$array[$key] = $val;
		$sql = "select * from 17koko_recommend_picture where recommend_id = $val[id]";
		$rs = mysql_query($sql,$conn);
		$arr = array();
		while($rows = mysql_fetch_assoc($rs)){
			$arr[] = $rows;
		}
		$array[$key]['recommend_picture'] = $arr;
	}
	foreach($array as $key=>$val){
		$sql = "insert into 17koko_recommend (title,category_id,url,picture,description,type,breakid,size,createtime)
		values 
		('$val[title]','1','$url','$picd','$description','2','1','$size','$time')";
		//echo $sql;
		if(mysql_query($sql,$conn1)){
			
			$id = mysql_insert_id();

			foreach($array[1] as $v){
				$sql = "insert into 17koko_recommend_picture (recommend_id,picture) values ('$id','$val')";
				if(mysql_query($sql,$conn1)){
					echo '发布成功';
				}
			}
			
		}
	}
}
?>